home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libshade / yacc.y < prev    next >
Encoding:
Text File  |  1994-08-09  |  47.3 KB  |  2,128 lines

  1. /* yacc.y                                   */
  2. /*                                       */
  3. /* Copyright (C) 1989, 1991, Craig E. Kolb                   */
  4. /* All rights reserved.                               */
  5. /*                                       */
  6. /* This software may be freely copied, modified, and redistributed,       */
  7. /* provided that this copyright notice is preserved on all copies.       */
  8. /*                                       */
  9. /* You may not distribute this software, in whole or in part, as part of   */
  10. /* any commercial product without the express consent of the authors.       */
  11. /*                                        */
  12. /* There is no warranty or other guarantee of fitness of this software       */
  13. /* for any purpose.  It is provided solely "as is".               */
  14. /* yacc.y,v 4.2 1994/08/09 22:11:03 explorer Exp */
  15. %{
  16. #include "rayshade.h"
  17.  
  18. #include "symtab.h"
  19. #include "builtin.h"
  20.  
  21. #include "libsurf/atmosphere.h"
  22. #include "libsurf/surface.h"
  23. #include "libtext/texture.h"
  24. #include "libimage/image.h"
  25. #include "libobj/geom.h"
  26. #include "liblight/light.h"
  27. #include "options.h"
  28. #include "stats.h"
  29. #include "viewing.h"
  30.  
  31. #include "libobj/blob.h"
  32. #include "libobj/box.h"
  33. #include "libobj/cone.h"
  34. #include "libobj/csg.h"
  35. #include "libobj/cylinder.h"
  36. #include "libobj/disc.h"
  37. #include "libobj/flame.h"    /* MANI */
  38. #include "libobj/grid.h"
  39. #include "libobj/hf.h"
  40. #include "libobj/fl.h"
  41. #include "libobj/instance.h"
  42. #include "libobj/list.h"
  43. #include "libobj/plane.h"
  44. #include "libobj/poly.h"
  45. #include "libobj/sphere.h"
  46. #include "libobj/sweptsph.h"
  47. #include "libobj/torus.h"
  48. #include "libobj/triangle.h"
  49. #include "libobj/rotspline.h"
  50. #include "libobj/ifs.h"
  51. #include "libobj/mountain.h"
  52. #include "libobj/fractalobject.h"
  53. #include "libobj/allocmatrix.h"
  54.  
  55. #include "liblight/point.h"
  56. #include "liblight/infinite.h"
  57. #include "liblight/spot.h"
  58. #include "liblight/jittered.h"
  59. #include "liblight/extended.h"
  60. #include "liblight/projector.h"
  61.  
  62. #include "libtext/blotch.h"
  63. #include "libtext/bump.h"
  64. #include "libtext/checker.h"
  65. #include "libtext/cloud.h"
  66. #include "libtext/fbm.h"
  67. #include "libtext/fbmbump.h"
  68. #include "libtext/gloss.h"
  69. #include "libtext/gradient.h"
  70. #include "libtext/imagetext.h"
  71. #include "libtext/marble.h"
  72. #include "libtext/mount.h"
  73. #include "libtext/sky.h"
  74. #include "libtext/stripe.h"
  75. #include "libtext/windy.h"
  76. #include "libtext/wood.h"
  77.  
  78. #include "libsurf/fog.h"
  79. #include "libsurf/fogdeck.h"
  80. #include "libsurf/mist.h"
  81.  
  82. #include "libcommon/rotate.h"
  83. #include "libcommon/scale.h"
  84. #include "libcommon/translate.h"
  85. #include "libcommon/xform.h"
  86.  
  87. Geom *NewAggregate();
  88. char yyfilename[BUFSIZ];            /* Input filename */
  89. GeomList *Defstack;                /* Geom definition stack. */
  90. int Npoints = 0;                /* # of points in Polypoints */
  91. float last_red, last_blue, last_green;          /* most recent color spec. */
  92. Surface *tmpsurf;                /* Working surface */
  93. SurfList *CurSurf;
  94. Texture *CurText;                /* Working list of textures */
  95. ImageText *Imagetext;                /* Working image texture */
  96. Trans *TransHead, *TransTail;            /* Linked list of current transformations */
  97. Atmosphere *CurEffect = (Atmosphere *)NULL;    /* Current atmos. effects */ 
  98. PointList *Polypoints;                /* List of vertices */
  99. MetaList *Metapoints, *Metapoint, *CMetapoints, *CMetapoint;
  100. PointPool *Pointpool;
  101. TrianglePool *Trianglepool;
  102. EntityPool *Entitypool;
  103. FractalEntity *CurrEntity;
  104. FractalTriangle *CurrTriangle;
  105. FractalPoint *CurrPoint;
  106. int    count;
  107.  
  108. extern FILE *yyin;                /* input file pointer */
  109. extern int yylineno;                /* Current line # in file */
  110. extern Atmosphere *AtmosEffects;        /* atmospheric effects */
  111. extern Medium TopMedium;            /* "air" */
  112. static IfsOptions ifsOptions;                   /* options for IFS object */
  113. static int ifsTransformRang;                    /* rang of IFS map */
  114. extern void    GeomAddToDefined(),
  115.         LightAddToDefined(),
  116.         SurfaceAddToDefined();
  117. extern Surface    *SurfaceGetNamed();
  118. extern Geom     *GeomGetNamed();
  119. int itemp;
  120. Float *Rcoeffs;                                 /* Coeffs for Rotspline */
  121. Vector cent[4];                    /* Points for SweptSph Curve */
  122. Float rad[4];                    /* Equation for SweptSph Radius */
  123.  
  124. %}
  125. %union {
  126.     char *c;
  127.     int i;
  128.     Float d;
  129.     Vector v;
  130.     Vec2d uv;
  131.     Color col;
  132.     Atmosphere *atmos;
  133.     Light *light;
  134.     Surface *surf;
  135.     Geom *obj;
  136.     Texture *text;
  137.     Mapping *map;
  138.     Trans *trans;
  139.     Expr *e;
  140.     SymtabEntry *sym;
  141.     IfsTransList *translist;
  142.         HeightValue   *heightvalues;
  143.         StartGridStruct *startgrid;
  144.         FractalClosure *fractalclosure;
  145.         PointPool *Fpointpool;
  146.         TrianglePool *Ftrianglepool;
  147.         EntityPool *Fentitypool;
  148.         TriangleList *Fentitytriangles;
  149. }
  150. %token <d> tFLOAT
  151. %token <c> tSTRING tFILENAME
  152. %token tAPERTURE tAPPLYSURF
  153. %token tBACKGROUND tBLOB tCBLOB tBLOTCH tBOX tBUMP tCONE tCYL tDIRECTIONAL tCURSURF
  154. %token tEXTENDED tEYEP tFBM tFBMBUMP tFLAME tFOCALDIST tFOG tFOGDECK tFOV tGLOSS tGRID
  155. %token tHEIGHTFIELD tLIGHT tLIST tLOOKP tMARBLE tMAXDEPTH tMIST tFRACLAND
  156. %token tJITTER tNOJITTER tDEFINE
  157. %token tOBJECT tOUTFILE  tSKY tDISC tDIFFERENCE tUNION tINTERSECT
  158. %token tPLANE tPOINT tPOLY tROTATE tSPOT tPRINT
  159. %token tSCALE tSCREEN tSPHERE tSURFACE
  160. %token tTHRESH tTRANSLATE tTRANSFORM tTRIANGLE tTRIANGLEUV tUP tEND
  161. %token tTEXTURE tCHECKER tWOOD tCONTRAST tCUTOFF tCLOUD tGRADIENT
  162. %token tAMBIENT tDIFFUSE tREFLECT tTRANSP tSPECULAR tSPECPOW
  163. %token tINDEX tATMOSPHERE tNOSHADOW tAREA tTRANSLU tTORUS
  164. %token tEYESEP tSHADOWTRANSP tREPORT tVERBOSE tQUIET tWINDOW tCROP tSTRIPE
  165. %token tMAP tUV tSPHERICAL tCYLINDRICAL tPLANAR
  166. %token tIMAGE tSMOOTH tCOMPONENT tTEXTSURF tRANGE tTILE tSTARTTIME tFRAMELENGTH
  167. %token tNAME tFILTER tGAUSS tBODY tSAMPLE tEXTINCT tWINDY tMOUNT
  168. %token tSHUTTER tFRAMES
  169. %token tPROJECTOR tTRUE tFALSE
  170. %token tROTSPLINE tCOEFFS
  171. %token tLINEAR tLOG tRADIAL tREVLOG tRANDOM
  172. %token tSWEPTSPH tBEZIER tXBEZIER tYBEZIER tZBEZIER tXCOEFFS tYCOEFFS tZCOEFFS
  173. %token tIFS tMINSIZE tBOUNDING
  174. %token tNORMALWEIGHTING tLOWPASS tHIGHPASS tCONSTANT 
  175. %token tMOUNTAIN
  176. %token tFRACTALOBJECT tFPOINTS tFTRIANGLES tFENTITIES tENTITY
  177. %type <i> IfsNormalWeightingMethod
  178. %type <c> Filename
  179. %type <e> AnimExpr MExpr ParenExpr
  180. %type <d> Expr Float GradStart GradStop
  181. %type <v> Vector
  182. %type <uv> Vec2d
  183. %type <col> Color Intensity Lightdef
  184. %type <text> Texturetype
  185. %type <i> SurfCompName IExpr CombineOp
  186. %type <i> BExpr
  187. %type <i> GradientType GradientShape GradientRand
  188. %type <atmos> EffectType
  189. %type <light> LightType
  190. %type <obj> PrimType Primitive TransTextObj
  191. %type <obj> Csg Aggregate Object TransObj ObjType
  192. %type <obj> Blob CBlob Box Cone Cylinder Disc Flame HeightField Plane Poly FracLand
  193. %type <obj> Sphere Triangle Torus AggregateType List Grid AggregateCreate
  194. %type <obj> NamedObject
  195. %type <obj> Rotspline
  196. %type <obj> SweptSph
  197. %type <surf> Surface OptSurface NamedSurf
  198. %type <surf> SurfSpec ModifyNamedSurf
  199. %type <map> Mapping MapMethod OptMapping
  200. %type <trans> TransformType
  201. %type <sym> Symtabent
  202. %type <obj> IfsCondensation IfsLeaves Ifs CIfs
  203. %type <translist> IfsTransforms
  204. %type <obj> Mountain
  205. %type <obj> FractalObject
  206. %type <heightvalues> HeightValues
  207. %type <startgrid> StartGrid
  208. %type <Fpointpool> FPointPool
  209. %type <Ftrianglepool> FTrianglePool
  210. %type <Fentitypool> FEntityPool
  211. %type <Fentitytriangles> FEntityTriangles
  212. %type <fractalclosure> FFractalClosure
  213.  
  214.  
  215. %left '+' '-'
  216. %left '*' '/' '%'
  217. %left UMINUS
  218. %right '^'
  219. %%
  220. Items        : /* empty */
  221.         | Items Item
  222.         ;
  223. Item        : Eyep
  224.         | Lookp
  225.         | Up
  226.         | Fov
  227.         | Screen
  228.         | Window
  229.         | Crop
  230.         | Report
  231.         | Aperture
  232.         | Focaldist
  233.         | Eyesep
  234.         | Maxdepth
  235.         | Sample
  236.         | Filter
  237.         | Contrast
  238.         | Cutoff
  239.         | Background
  240.         | Shadowtransp
  241.         | Light
  242.         | SurfDef
  243.         | CurSurf
  244.         | Outfile
  245.         | Instance
  246.         | NameObject
  247.         | GlobalEffects
  248.         | Define
  249.         | Frames
  250.         | Starttime
  251.         | Shutter
  252.         | Framelength
  253.             | Print
  254.         ;
  255. Instance    : TransTextObj
  256.         {
  257.             if ($1) {
  258.                 /*
  259.                  * Add instance to current object.
  260.                  */
  261.                 $1->next = Defstack->obj->next;
  262.                 Defstack->obj->next = $1;
  263.             }
  264.         }
  265. TransTextObj    : TransObj Textures
  266.         {
  267.             if ($$ && CurText) {
  268.                 $$->texture = TextAppend(CurText, $$->texture);
  269.             }
  270.             CurText = (Texture *)NULL;
  271.         }
  272.         ;    
  273. TransObj    : Object Transforms
  274.         {
  275.             $$ = $1;
  276.             if ($$ != (Geom *)NULL) {
  277.                 if (TransHead) {
  278.                     $$->trans = TransHead;
  279.                     $$->transtail = TransTail;
  280.                     /*
  281.                      * We compose non-animated tranformation lists,
  282.                      * so we're only animated if it's one long,
  283.                      * or it's animated itself.
  284.                      */
  285.                     if ($$->trans->assoc || $$->trans->next)
  286.                         /* geometry is animated...*/
  287.                         $$->animtrans = TRUE;
  288.                 }
  289.             }
  290.         }
  291.         ;
  292. Object        : ObjType
  293.         {
  294.             if ($$)
  295.                 StatsAddRep($$);
  296.         }
  297.         | NamedObject
  298.         ;
  299. ObjType        : Primitive
  300.         | Aggregate
  301.         ;
  302. Primitive    : PrimType
  303.         {
  304.             if ($$)
  305.                 $$->prims = 1;    /* one primitive */
  306.         }
  307.         ;
  308. PrimType    : Plane
  309.         | Sphere
  310.         | Box
  311.         | Triangle
  312.         | Cylinder
  313.         | Cone
  314.         | Poly
  315.         | HeightField
  316.         | Disc
  317.         | Torus
  318.         | Blob
  319.                 | CBlob
  320.                 | FracLand
  321.                 | Rotspline
  322.         | SweptSph
  323.         | Flame
  324.                 | Ifs
  325.                 | CIfs
  326.                 | Mountain
  327.                 | FractalObject
  328.         ;
  329. NameObject    : tNAME tSTRING TransTextObj
  330.         {
  331.             if ($3) {
  332.                 $3->name = $2;
  333.                 GeomAddToDefined($3);
  334.             }
  335.         };
  336. Aggdefs        : Aggdefs Aggdef
  337.         |
  338.         ;
  339. Aggdef        : Instance
  340.         | SurfDef
  341.         | CurSurf
  342.         | NameObject
  343.         ;
  344. Textures    : Textures Texture
  345.         |
  346.         ;
  347. Texture        : tTEXTURE Texturetype Transforms
  348.         {
  349.             if ($2 != (Texture *)NULL) {
  350.                 /*
  351.                  * Set transformation information.
  352.                  */
  353.                 if (TransHead) {
  354.                     $2->trans = TransHead;
  355.                     /*
  356.                      * We compose non-animated tranformation lists,
  357.                      * so we're only animated if it's one long,
  358.                      * or it's animated itself.
  359.                      */
  360.                     if ($2->trans->assoc || $2->trans->next)
  361.                         /* texture transformation is animated...*/
  362.                         $2->animtrans = TRUE;
  363.                 }
  364.                 /*
  365.                  * Walk to the end of list of textures and
  366.                  * append new texture.  This is done so that
  367.                  * textures are applied in the expected order.
  368.                  */
  369.                 CurText = TextAppend($2, CurText);
  370.             }
  371.         }
  372.         ;
  373. Texturetype    : tCHECKER Surface
  374.         {
  375.             $$ = TextCheckerCreate($2);
  376.         }
  377.         | tBLOTCH Expr Surface
  378.         {
  379.             $$ = TextBlotchCreate($2, $3);
  380.         }
  381.         | tBUMP Expr
  382.         {
  383.             $$ = TextBumpCreate($2);
  384.         }
  385.         | tMARBLE
  386.         {
  387.             $$ = TextMarbleCreate((char *)NULL);
  388.         }
  389.         | tMARBLE Filename
  390.         {
  391.             $$ = TextMarbleCreate($2);
  392.         }
  393.         | tFBM Expr Expr Expr Expr IExpr Expr
  394.         {
  395.             $$ = TextFBmCreate($2, $3, $4, $5, $6, $7,
  396.                         (char *)NULL);
  397.         }
  398.         | tFBM Expr Expr Expr Expr IExpr Expr Filename
  399.         {
  400.             $$ = TextFBmCreate($2, $3, $4, $5, $6, $7, $8);
  401.         }
  402.         | tFBMBUMP Expr Expr Expr Expr IExpr 
  403.         {
  404.             $$ = TextFBmBumpCreate($2, $3, $4, $5, $6);
  405.         }
  406.         | tWOOD
  407.         {
  408.             $$ = TextWoodCreate();
  409.         }
  410.         | tGLOSS Expr 
  411.         {
  412.             $$ = TextGlossCreate($2);
  413.         }
  414.         | tCLOUD Expr Expr Expr IExpr Expr Expr Expr
  415.         {
  416.             $$ = TextCloudCreate($2, $3, $4, $5, $6, $7, $8);
  417.         }
  418.         | tSKY Expr Expr Expr IExpr Expr Expr
  419.         {
  420.             $$ = TextSkyCreate($2, $3, $4, $5, $6, $7);
  421.         }
  422.         | ImageText
  423.         {
  424.             /*
  425.              * Image texturing has so many options
  426.              * that specification is keyword-based.
  427.              */
  428.             if (Imagetext->image == (Image *)NULL)
  429.                 $$ = (Texture *)NULL;
  430.             else
  431.                 $$ = TextCreate(Imagetext, ImageTextApply);
  432.             Imagetext = (ImageText *)NULL;
  433.         }
  434.         | tSTRIPE Surface Expr Expr OptMapping
  435.         {
  436.             $$ = TextStripeCreate($2, $3, $4, $5);
  437.         }
  438.         | tWINDY Expr Expr Expr Expr IExpr Expr Expr Expr
  439.         {
  440.             $$ = TextWindyCreate($2, $3, $4, $5, $6, $7, $8, $9);
  441.         }
  442.         | tMOUNT Filename Expr Expr
  443.         {
  444.             $$ = TextMountCreate($2, $3, $4);
  445.         }
  446.         | tGRADIENT NamedSurf NamedSurf GradientShape GradStart GradStop GradientType GradientRand
  447.         {
  448.             $$ = TextGradientCreate($2, $3, $4, $5, $6, $7, $8);
  449.         }
  450.         ;
  451. GradientType    :/* empty */
  452.         {
  453.             $$ = LINEAR;
  454.         }
  455.         | tLINEAR
  456.         {
  457.             $$ = LINEAR;
  458.         }
  459.         | tLOG
  460.         {
  461.             $$ = LOG;
  462.         }
  463.         | tREVLOG
  464.         {
  465.             $$ = REVLOG;
  466.         }
  467.         ;
  468. GradientShape    : /* empty */
  469.         {
  470.             $$ = PLANAR;
  471.         }
  472.         | tPLANAR
  473.         {
  474.             $$ = PLANAR;
  475.         }
  476.         | tRADIAL
  477.         {
  478.             $$ = RADIAL;
  479.         }
  480.         | tSPHERICAL
  481.         {
  482.             $$ = SPHERICAL;
  483.         }
  484.         ;
  485. GradStart    : /* empty */
  486.         {
  487.             $$ = 0.0;
  488.         }
  489.         | Expr
  490.         {
  491.             $$ = $1;
  492.         }
  493.         ;
  494. GradStop    : /* empty */
  495.         {
  496.             $$ = 1.0;
  497.         }
  498.         | Expr
  499.         {
  500.             $$ = $1;
  501.         }
  502.         ;
  503. GradientRand    : /* empty */
  504.         {
  505.             $$ = NO;
  506.         }
  507.         | tRANDOM
  508.         {
  509.             $$ = YES;
  510.         }
  511.         ;
  512. ProjectorText   : ProjectorTextType ProjectorTextOptions
  513.                 ;
  514. ProjectorTextType: tPROJECTOR Filename
  515.                 {
  516.                         Imagetext = ImageTextCreate($2);
  517.                 }
  518.                 ;
  519. ProjectorTextOptions: ProjectorTextOptions ProjectorTextOption
  520.         | /* EMPTY */
  521.         ;
  522. ProjectorTextOption: tTILE Expr Expr
  523.         {
  524.             Imagetext->tileu = $2;
  525.             Imagetext->tilev = $3;
  526.         }
  527.         | tSMOOTH
  528.         {
  529.             Imagetext->smooth = TRUE;
  530.         };
  531. ImageText    : ImageTextType ImageTextOptions
  532.         ;
  533. ImageTextType    : tIMAGE Filename
  534.         {
  535.             Imagetext = ImageTextCreate($2);
  536.         }
  537.         ;
  538. ImageTextOptions: ImageTextOptions ImageTextOption
  539.         | /* EMPTY */
  540.         ;
  541. ImageTextOption: tCOMPONENT SurfCompName
  542.         {
  543.             /* set texture to modify given component */    
  544.             ImageTextSetComponent(Imagetext, $2);
  545.         }
  546.         | tTILE Expr Expr
  547.         {
  548.             Imagetext->tileu = $2;
  549.             Imagetext->tilev = $3;
  550.         }
  551.         | tTEXTSURF Surface
  552.         {
  553.             Imagetext->surf = $2;
  554.         }
  555.         | tRANGE Expr Expr
  556.         {
  557.             Imagetext->hi = $2;
  558.             Imagetext->lo = $3;
  559.         }
  560.         | tSMOOTH
  561.         {
  562.             Imagetext->smooth = TRUE;
  563.         }
  564.         | Mapping
  565.         {
  566.             Imagetext->mapping = $1;
  567.         };
  568. NamedObject    : tOBJECT Surface tSTRING
  569.         {
  570.             Geom *otmp;
  571.             /*
  572.              * Create an instance of the named object.
  573.              */
  574.             otmp = GeomGetNamed($3);
  575.             if (otmp == (Geom *)NULL)
  576.                 RLerror(RL_PANIC,
  577.                   "There is no object named \"%s\".", $3);
  578.             $$ = GeomInstanceCreate(otmp);
  579.             $$->surf = $2;
  580.             $$->prims = otmp->prims;
  581.         }
  582.         | tOBJECT tSTRING
  583.         {
  584.             Geom *otmp;
  585.  
  586.             otmp = GeomGetNamed($2);
  587.             if (otmp == (Geom *)NULL)
  588.                 RLerror(RL_PANIC,
  589.                   "There is no object named \"%s\".", $2);
  590.             $$ = GeomInstanceCreate(otmp);
  591.             $$->surf = CurSurf->surf;
  592.             $$->prims = otmp->prims;
  593.         };
  594. Transforms    : Transforms PostTransform
  595.         | /* empty */
  596.         {
  597.             TransHead = TransTail = (Trans *)NULL;
  598.         };
  599. PostTransform    : TransformType
  600.         {
  601.             if (TransHead == (Trans *)NULL) {
  602.                 /* we're the list, head and tail */
  603.                 TransHead = TransTail = $1;
  604.             } else {
  605.                 if ($1->animated || TransTail->animated) {
  606.                     /* new tail */
  607.                     $1->prev = TransTail;
  608.                     TransTail->next = $1;
  609.                     TransTail = $1;
  610.                 } else {
  611.                     /* collapse with tail */
  612.                     TransCompose(TransTail, $1, TransTail);
  613.                     TransFree($1);
  614.                 }
  615.             }
  616.         }
  617.         ;
  618. TransformType    : tSCALE AnimExpr AnimExpr AnimExpr
  619.         {
  620.             $$ = TransScaleCreate();
  621.             TransScaleSetX($$, $2);
  622.             TransScaleSetY($$, $3);
  623.             TransScaleSetZ($$, $4);
  624.             if (!$$->animated)
  625.                 TransPropagate($$);
  626.                 
  627.         }
  628.         | tTRANSLATE AnimExpr AnimExpr AnimExpr
  629.         {
  630.             $$ = TransTranslateCreate();
  631.             TransTranslateSetX($$, $2);
  632.             TransTranslateSetY($$, $3);
  633.             TransTranslateSetZ($$, $4);
  634.             if (!$$->animated)
  635.                 TransPropagate($$);
  636.         }
  637.         | tROTATE AnimExpr AnimExpr AnimExpr AnimExpr
  638.         {
  639.             $$ = TransRotateCreate();
  640.             TransRotateSetX($$, $2);
  641.             TransRotateSetY($$, $3);
  642.             TransRotateSetZ($$, $4);
  643.             TransRotateSetTheta($$, $5);
  644.             if (!$$->animated)
  645.                 TransPropagate($$);
  646.         }
  647.         | tTRANSFORM    AnimExpr AnimExpr AnimExpr
  648.                 AnimExpr AnimExpr AnimExpr
  649.                 AnimExpr AnimExpr AnimExpr
  650.         {
  651.             $$ = TransXformCreate();
  652.             TransXformSetX0($$, $2);
  653.             TransXformSetY0($$, $3);
  654.             TransXformSetZ0($$, $4);
  655.             TransXformSetX1($$, $5);
  656.             TransXformSetY1($$, $6);
  657.             TransXformSetZ1($$, $7);
  658.             TransXformSetX2($$, $8);
  659.             TransXformSetY2($$, $9);
  660.             TransXformSetZ2($$, $10);
  661.             if (!$$->animated)
  662.                 TransPropagate($$);
  663.         }
  664.         | tTRANSFORM    AnimExpr AnimExpr AnimExpr
  665.                 AnimExpr AnimExpr AnimExpr
  666.                 AnimExpr AnimExpr AnimExpr
  667.                 AnimExpr AnimExpr AnimExpr
  668.         {
  669.             $$ = TransXformCreate();
  670.             TransXformSetX0($$, $2);
  671.             TransXformSetY0($$, $3);
  672.             TransXformSetZ0($$, $4);
  673.             TransXformSetX1($$, $5);
  674.             TransXformSetY1($$, $6);
  675.             TransXformSetZ1($$, $7);
  676.             TransXformSetX2($$, $8);
  677.             TransXformSetY2($$, $9);
  678.             TransXformSetZ2($$, $10);
  679.             TransXformSetXt($$, $11);
  680.             TransXformSetYt($$, $12);
  681.             TransXformSetZt($$, $13);
  682.             if (!$$->animated)
  683.                 TransPropagate($$);
  684.         };
  685. Eyep        : tEYEP Vector Transforms
  686.         {
  687.             Camera.pos = $2;
  688.             /*
  689.              * Eye can be transformed...
  690.             if (CurMatrix) {
  691.                 PointTransform(&Camera.pos, CurMatrix);
  692.                 free((voidstar)CurMatrix);
  693.                 CurMatrix = (Matrix*)NULL;
  694.             }
  695.              */
  696.         }
  697.         ;
  698. Lookp        : tLOOKP Vector
  699.         {
  700.             Camera.lookp = $2;
  701.         }
  702.         ;
  703. Up        : tUP Vector
  704.         {
  705.             Camera.up = $2;
  706.         }
  707.         ;
  708. Fov        : tFOV Expr Expr
  709.         {
  710.             Camera.hfov = $2;
  711.             Camera.vfov = $3;
  712.         }
  713.         | tFOV Expr
  714.         {
  715.             Camera.hfov = $2;
  716.             Camera.vfov = UNSET;
  717.         }
  718.         ;
  719. Sample        : tSAMPLE IExpr tJITTER
  720.         {
  721.             if (!Options.samples_set)
  722.                 Options.samples = $2;
  723.             if (!Options.jitter_set)
  724.                 Options.jitter = TRUE;
  725.         }
  726.         | tSAMPLE IExpr tNOJITTER
  727.         {
  728.             if (!Options.samples_set)
  729.                 Options.samples = $2;
  730.             if (!Options.jitter_set)
  731.                 Options.jitter = FALSE;
  732.         }
  733.         | tSAMPLE IExpr
  734.         {
  735.             if (!Options.samples_set)
  736.                 Options.samples = $2;
  737.         }
  738.         ;
  739. Filter        : tFILTER tBOX Expr
  740.         {
  741.             Options.gaussian = FALSE;
  742.             Options.filterwidth = $3;
  743.         }
  744.         | tFILTER tBOX
  745.         {
  746.             Options.gaussian = FALSE;
  747.         }    
  748.         | tFILTER tGAUSS Expr
  749.         {
  750.             Options.gaussian = TRUE;
  751.             Options.filterwidth = $3;
  752.         }
  753.         | tFILTER tGAUSS
  754.         {
  755.             Options.gaussian = TRUE;
  756.         };
  757. Starttime    : tSTARTTIME Expr
  758.         {
  759.             Options.starttime = $2;
  760.         };
  761. Frames        : tFRAMES IExpr
  762.         {
  763.             if (!Options.totalframes_set)
  764.                 Options.totalframes = $2;
  765.         };
  766. Framelength    : tFRAMELENGTH Expr
  767.         {
  768.             Options.framelength = $2;
  769.         };
  770. Shutter        : tSHUTTER Expr
  771.         {
  772.             Options.shutterspeed = $2;
  773.         };
  774. Contrast    : tCONTRAST Expr Expr Expr
  775.         {
  776.             if (!Options.contrast_set) {
  777.                 Options.contrast.r = $2;
  778.                 Options.contrast.g = $3;
  779.                 Options.contrast.b = $4;
  780.             }
  781.         }
  782.         ;
  783. Cutoff        : tCUTOFF Intensity
  784.         {
  785.             if (!Options.cutoff_set)
  786.                 Options.cutoff = $2;
  787.         }
  788.         ;
  789. Screen        : tSCREEN IExpr IExpr 
  790.         {
  791.             if (!Options.resolution_set) {
  792.                 Screen.xres = $2;
  793.                 Screen.yres = $3;
  794.             }
  795.         }
  796.         ;
  797. Window        : tWINDOW IExpr IExpr IExpr IExpr
  798.         {
  799.             if (!Options.window_set) {
  800.                 Options.window[LOW][X] = $2;
  801.                 Options.window[HIGH][X] = $3;
  802.                 Options.window[LOW][Y] = $4;
  803.                 Options.window[HIGH][Y] = $5;
  804.                 /*
  805.                  * We must let ViewingSetup know
  806.                  * that a window has been defined.
  807.                  */
  808.                 Options.window_set = TRUE;
  809.             }
  810.         }
  811.         ;
  812. Crop        : tCROP Expr Expr Expr Expr
  813.         {
  814.             if (!Options.crop_set) {
  815.                 Options.crop[LOW][X] = $2;
  816.                 Options.crop[HIGH][X] = $3;
  817.                 Options.crop[LOW][Y] = $4;
  818.                 Options.crop[HIGH][Y] = $5;
  819.             }
  820.         }
  821.         ;
  822. Report        : tREPORT Verbose Quiet IExpr Filename
  823.         {
  824.             if (!Options.freq_set)
  825.                 Options.report_freq = $4;
  826.             if (Options.statsname == (char *)NULL)
  827.                 Options.statsname = strsave($5);
  828.         }
  829.         | tREPORT Verbose Quiet IExpr
  830.         {
  831.             if (!Options.freq_set)
  832.                 Options.report_freq = $4;
  833.         }
  834.         | tREPORT Verbose Quiet Filename
  835.         {
  836.             if (Options.statsname == (char *)NULL)
  837.                 Options.statsname = strsave($4);
  838.         }
  839.         | tREPORT Verbose Quiet
  840.         ;
  841. Verbose        : tVERBOSE
  842.         { Options.verbose = TRUE; }
  843.         |
  844.         ;
  845. Quiet        : tQUIET
  846.         { Options.quiet = TRUE; }
  847.         |
  848.         ;
  849. Aperture    : tAPERTURE Expr
  850.         {
  851.             Camera.aperture = $2;
  852.         }
  853.         ;
  854. Focaldist    : tFOCALDIST Expr
  855.         {
  856.             Camera.focaldist = $2;
  857.         }
  858.         ;
  859. Eyesep        : tEYESEP Expr
  860.         {
  861.             if (!Options.eyesep_set)
  862.                 Options.eyesep = $2;
  863.         }
  864.         ;
  865. Maxdepth    : tMAXDEPTH IExpr
  866.         {
  867.             if (!Options.maxdepth_set)
  868.                 Options.maxdepth = $2;
  869.         }
  870.         ;
  871. Background    : tBACKGROUND Color
  872.         {
  873.             Screen.background = $2;
  874.         }
  875.         ;
  876. Shadowtransp    : tSHADOWTRANSP
  877.         {
  878.             Options.shadowtransp = !Options.shadowtransp;
  879.         }
  880.         ;
  881. Light        : LightType
  882.         {
  883.             LightAddToDefined($1);
  884.         }
  885.         | LightType tNOSHADOW
  886.         {
  887.             $1->shadow = FALSE;
  888.             LightAddToDefined($1);
  889.         }
  890.         | tLIGHT Intensity tAMBIENT
  891.         {
  892.             Options.ambient = $2;
  893.         }
  894.         | Lightdef tAREA Vector Vector IExpr Vector IExpr
  895.         {
  896.             extern void AreaLightCreate();
  897.             /* Area light is strange in that the
  898.              * Creation routine does the installation.
  899.              */
  900.             AreaLightCreate(&$1, &$3, &$4, $5, &$6, $7, TRUE);
  901.         }
  902.         | Lightdef tAREA Vector Vector IExpr Vector IExpr tNOSHADOW
  903.         {
  904.             extern void AreaLightCreate();
  905.             /* Area light is strange in that the
  906.              * Creation routine does the installation.
  907.              */
  908.             AreaLightCreate(&$1, &$3, &$4, $5, &$6, $7, FALSE);
  909.         };
  910. LightType    : Lightdef tPOINT Vector
  911.         {
  912.             $$ = LightPointCreate(&$1, &$3);
  913.         }
  914.         | Lightdef tDIRECTIONAL Vector
  915.         {
  916.             $$ = LightInfiniteCreate(&$1, &$3);
  917.         }
  918.         | Lightdef tEXTENDED Expr Vector
  919.         {
  920.             $$ = LightExtendedCreate(&$1, $3, &$4);
  921.         }
  922.         | Lightdef tSPOT Vector Vector Expr
  923.         {
  924.             $$ = LightSpotCreate(&$1, &$3, &$4, $5, 0., 0.);
  925.         }
  926.         | Lightdef tSPOT Vector Vector Expr Expr Expr
  927.         {
  928.             /* light <intens> spot from <to> coef inner_rad
  929.                     outer_rad */
  930.             $$ = LightSpotCreate(&$1, &$3, &$4, $5, $6, $7);
  931.         }
  932.                 | Lightdef ProjectorText Vector Vector Vector Expr Expr BExpr
  933.                 {
  934.                 /* light projector <name> <from> <to> <up> <uangle> <vangle> <atten> */
  935.                         /*
  936.                          * Image texturing has so many options
  937.                          * that specification is keyword-based.
  938.                          */
  939.                         if (Imagetext->image == (Image *)NULL) {
  940.                             RLerror(RL_WARN,
  941.                             "Spotlight substituted for degenerate image light.\n");
  942.                             $$=LightSpotCreate(&$1, &$3, &$4,
  943.                                     2.0, 0., 0.);
  944.                         }
  945.                         else {
  946.                             $$=LightProjectorCreate(&$1,
  947.                 &$3,&$4,&$5,Imagetext,$6,$7,$8);
  948.                         }
  949.  
  950.                         Imagetext = (ImageText *)NULL;
  951.                 }
  952.         ;
  953. Lightdef    : tLIGHT Intensity
  954.         {
  955.             $$ = $2;
  956.         }
  957.         ;
  958. CurSurf        : tAPPLYSURF Surface
  959.         {
  960.             CurSurf->surf = $2;
  961.         }
  962.         ;
  963. OptSurface    : Surface
  964.         | /* EMPTY */
  965.         {
  966.             $$ = CurSurf->surf;
  967.         }
  968.         ;
  969. Surface        : NamedSurf
  970.         | ModifyNamedSurf
  971.         | SurfSpec
  972.         ;
  973. NamedSurf    : tSTRING
  974.         {
  975.             $$ = SurfaceGetNamed($1);
  976.             /*
  977.              * Free up memory allocated for surf name.
  978.              * We bother doing this because for large models
  979.              * converted from 3.0, surfnames this can account
  980.              * for lots o' bytes.
  981.              */
  982.             free((voidstar)$1);
  983.         }
  984.         | tCURSURF
  985.         {
  986.             extern Surface DefaultSurface;
  987.  
  988.             if (CurSurf->surf)
  989.                 $$ = CurSurf->surf;
  990.             else
  991.                 $$ = &DefaultSurface;
  992.         }
  993.         ;
  994. ModifyNamedSurf : CopyNamedSurf SurfComponent SurfComponents
  995.         {
  996.             $$ = tmpsurf;
  997.             tmpsurf = (Surface *)NULL;
  998.         }
  999.         | CopyCurSurf SurfComponent SurfComponents
  1000.         {
  1001.             $$ = tmpsurf;
  1002.             tmpsurf = (Surface *)NULL;
  1003.         }
  1004.         ;
  1005. CopyNamedSurf    : tSTRING
  1006.         {
  1007.             tmpsurf = SurfaceCopy(SurfaceGetNamed($1));
  1008.         }
  1009.         ;
  1010. CopyCurSurf    : tCURSURF
  1011.         {
  1012.             extern Surface DefaultSurface;
  1013.             if (CurSurf->surf)
  1014.                 tmpsurf = SurfaceCopy(CurSurf->surf);
  1015.             else
  1016.                 tmpsurf = SurfaceCopy(&DefaultSurface);
  1017.         }
  1018.         ;
  1019. SurfSpec    : SurfComponent SurfComponents
  1020.         {
  1021.             $$ = tmpsurf;
  1022.             tmpsurf = (Surface *)NULL;
  1023.         } 
  1024.         ;
  1025. SurfDef        : tSURFACE tSTRING Surface
  1026.         {
  1027.             tmpsurf = SurfaceCopy($3);
  1028.             tmpsurf->name = strsave($2);
  1029.             SurfaceAddToDefined(tmpsurf);
  1030.             tmpsurf = (Surface *)NULL;
  1031.         }
  1032.         | tSURFACE tSTRING
  1033.         {
  1034.             /* black surface */
  1035.             tmpsurf = SurfaceCreate();
  1036.             tmpsurf->name = strsave($2);
  1037.             SurfaceAddToDefined(tmpsurf);
  1038.             tmpsurf = (Surface *)NULL;
  1039.         }
  1040.         ;
  1041. SurfComponents    : SurfComponents SurfComponent
  1042.         | /* EMPTY */
  1043.         ;
  1044. SurfComponent    : Ambient
  1045.         | Diffuse
  1046.         | Specular
  1047.         | Specpow
  1048.         | Body
  1049.         | Reflect
  1050.         | Transp
  1051.         | Extinct
  1052.         | Index
  1053.         | Translu
  1054.         | Noshadow
  1055.         ;
  1056. Ambient        : tAMBIENT Color
  1057.         {
  1058.             if (tmpsurf == (Surface *)NULL)
  1059.                 tmpsurf = SurfaceCreate();
  1060.             tmpsurf->amb = $2;
  1061.         }
  1062.         ;
  1063. Diffuse        : tDIFFUSE Color
  1064.         {
  1065.             if (tmpsurf == (Surface *)NULL)
  1066.                 tmpsurf = SurfaceCreate();
  1067.             tmpsurf->diff = $2;
  1068.         }
  1069.         ;
  1070. Specular    : tSPECULAR Color
  1071.         {
  1072.             if (tmpsurf == (Surface *)NULL)
  1073.                 tmpsurf = SurfaceCreate();
  1074.             tmpsurf->spec = $2;
  1075.         }
  1076.         ;
  1077. Body        : tBODY Color
  1078.         {
  1079.             if (tmpsurf == (Surface *)NULL)
  1080.                 tmpsurf = SurfaceCreate();
  1081.             tmpsurf->body = $2;
  1082.         };
  1083. Extinct        : tEXTINCT Expr
  1084.         {
  1085.             if (tmpsurf == (Surface *)NULL)
  1086.                 tmpsurf = SurfaceCreate();
  1087.             tmpsurf->statten = $2;
  1088.         };
  1089. Specpow        : tSPECPOW Expr
  1090.         {
  1091.             if (tmpsurf == (Surface *)NULL)
  1092.                 tmpsurf = SurfaceCreate();
  1093.             tmpsurf->srexp = $2;
  1094.         }
  1095.         ;
  1096. Reflect        : tREFLECT Expr
  1097.         {
  1098.             if (tmpsurf == (Surface *)NULL)
  1099.                 tmpsurf = SurfaceCreate();
  1100.             tmpsurf->reflect = $2;
  1101.         }
  1102.         ;
  1103. Transp        : tTRANSP Expr
  1104.         {
  1105.             if (tmpsurf == (Surface *)NULL)
  1106.                 tmpsurf = SurfaceCreate();
  1107.             tmpsurf->transp = $2;
  1108.         }
  1109.         ;
  1110. Index        : tINDEX Expr
  1111.         {
  1112.             if (tmpsurf == (Surface *)NULL)
  1113.                 tmpsurf = SurfaceCreate();
  1114.             tmpsurf->index = $2;
  1115.         }
  1116.         ;
  1117. Translu        : tTRANSLU Expr Color Expr
  1118.         {
  1119.             if (tmpsurf == (Surface *)NULL)
  1120.                 tmpsurf = SurfaceCreate();
  1121.             tmpsurf->translucency = $2;
  1122.             tmpsurf->translu = $3;
  1123.             tmpsurf->stexp = $4;
  1124.         }
  1125.         ;
  1126. Noshadow    : tNOSHADOW
  1127.         {
  1128.             if (tmpsurf == (Surface *)NULL)
  1129.                 tmpsurf = SurfaceCreate();
  1130.             tmpsurf->noshadow = TRUE;
  1131.         }
  1132.         ;
  1133. SweptSph    : tSWEPTSPH OptSurface SweptSphCenter SweptSphRadius
  1134.         {
  1135.             $$ = GeomSweptSphCreate(cent, rad);
  1136.             if ($$)
  1137.                 $$->surf = $2;
  1138.             {
  1139.                 int i;
  1140.                 for (i = 0; i < 4; i++){
  1141.                     cent[i].x = 0.0;
  1142.                     cent[i].y = 0.0;
  1143.                     cent[i].z = 0.0;
  1144.                 }
  1145.             }
  1146.         }
  1147.         ;
  1148. SweptSphCenter    : /* empty */
  1149.         | tBEZIER Expr Expr Expr  Expr Expr Expr  Expr Expr Expr  Expr Expr Expr
  1150.         {
  1151.  
  1152.             /* equations for Bezier curve */
  1153.         
  1154.  
  1155.             cent[0].x = $2;
  1156.             cent[0].y = $3;
  1157.             cent[0].z = $4;
  1158.  
  1159.             cent[1].x = -3*$2 + 3*$5;
  1160.             cent[1].y = -3*$3 + 3*$6;
  1161.             cent[1].z = -3*$4 + 3*$7;
  1162.  
  1163.             cent[2].x = 3*$2 - 6*$5 + 3*$8;
  1164.             cent[2].y = 3*$3 - 6*$6 + 3*$9;
  1165.             cent[2].z = 3*$4 - 6*$7 + 3*$10;
  1166.  
  1167.             cent[3].x = -$2 + 3*$5 - 3*$8 + $11;
  1168.             cent[3].y = -$3 + 3*$6 - 3*$9 + $12;
  1169.             cent[3].z = -$4 + 3*$7 - 3*$10 + $13;
  1170.  
  1171.         }
  1172.         | tCOEFFS Expr Expr Expr Expr   Expr Expr Expr Expr  Expr Expr Expr Expr
  1173.         {
  1174.  
  1175.             cent[0].x = $2;
  1176.             cent[1].x = $3;
  1177.             cent[2].x = $4;
  1178.             cent[3].x = $5;
  1179.  
  1180.             cent[0].y = $6;
  1181.             cent[1].y = $7;
  1182.             cent[2].y = $8;
  1183.             cent[3].y = $9;
  1184.  
  1185.             cent[0].z = $10;
  1186.             cent[1].z = $11;
  1187.             cent[2].z = $12;
  1188.             cent[3].z = $13;
  1189.         }
  1190.         | tXBEZIER Expr Expr Expr Expr SweptSphCenter
  1191.         {
  1192.             cent[0].x = $2;
  1193.             cent[1].x = -3*$2 + 3*$3;
  1194.             cent[2].x = 3*$2 - 6*$3 + 3*$4;
  1195.             cent[3].x = -$2 + 3*$3 - 3*$4 + $5;
  1196.         }
  1197.         | tYBEZIER Expr Expr Expr Expr SweptSphCenter
  1198.         {
  1199.             cent[0].y = $2;
  1200.             cent[1].y = -3*$2 + 3*$3;
  1201.             cent[2].y = 3*$2 - 6*$3 + 3*$4;
  1202.             cent[3].y = -$2 + 3*$3 - 3*$4 + $5;
  1203.         }
  1204.         | tZBEZIER Expr Expr Expr Expr SweptSphCenter
  1205.         {
  1206.             cent[0].z = $2;
  1207.             cent[1].z = -3*$2 + 3*$3;
  1208.             cent[2].z = 3*$2 - 6*$3 + 3*$4;
  1209.             cent[3].z = -$2 + 3*$3 - 3*$4 + $5;
  1210.         }
  1211.         | tXCOEFFS Expr Expr Expr Expr SweptSphCenter
  1212.         {
  1213.             cent[0].x = $2;
  1214.             cent[1].x = $3;
  1215.             cent[2].x = $4;
  1216.             cent[3].x = $5;
  1217.         }
  1218.         | tYCOEFFS Expr Expr Expr Expr SweptSphCenter
  1219.         {
  1220.             cent[0].y = $2;
  1221.             cent[1].y = $3;
  1222.             cent[2].y = $4;
  1223.             cent[3].y = $5;
  1224.         }
  1225.         | tZCOEFFS Expr Expr Expr Expr SweptSphCenter
  1226.         {
  1227.             cent[0].z = $2;
  1228.             cent[1].z = $3;
  1229.             cent[2].z = $4;
  1230.             cent[3].z = $5;
  1231.         }
  1232.         ;
  1233. SweptSphRadius    : Expr Expr Expr Expr
  1234.         {
  1235.             rad[0] = $1;
  1236.             rad[1] = $2;
  1237.             rad[2] = $3;
  1238.             rad[3] = $4;
  1239.         }
  1240.         ;
  1241. HeightField    : tHEIGHTFIELD Surface Filename
  1242.         {
  1243.             $$ = GeomHfCreate($3);
  1244.             if ($$)
  1245.                 $$->surf = $2;
  1246.         }
  1247.         | tHEIGHTFIELD Filename
  1248.         {
  1249.             $$ = GeomHfCreate($2);
  1250.         }
  1251.         ;
  1252. FracLand        : tFRACLAND Surface IExpr IExpr
  1253.                 {
  1254.                         $$ = GeomFlCreate($3,$4);
  1255.                         if ($$)
  1256.                                 $$->surf = $2;
  1257.                 }
  1258.                 | tFRACLAND IExpr IExpr
  1259.                 {
  1260.                         $$ = GeomFlCreate($2,$3);
  1261.                 }
  1262.                 ;
  1263. Poly        : tPOLY OptSurface Polypoints
  1264.         {
  1265.             $$ = GeomPolygonCreate(Polypoints, Npoints,
  1266.                 Options.flipnorm);
  1267.             if ($$)
  1268.                 $$->surf = $2;
  1269.             Polypoints = (PointList *)NULL;
  1270.             Npoints = 0;
  1271.         }
  1272.         ;
  1273. Polypoints    : /* empty */
  1274.         | Polypoints Polypoint
  1275.         ;
  1276. Polypoint    : Vector
  1277.         {
  1278.             PointList *ptmp;
  1279.  
  1280.             ptmp = (PointList *)Malloc(sizeof(PointList));
  1281.             ptmp->vec = $1;
  1282.             ptmp->next = Polypoints;
  1283.             Polypoints = ptmp;
  1284.             Npoints++;
  1285.         }
  1286.         ;
  1287. Mountain        : tMOUNTAIN OptSurface Vec2d Vec2d Float Float Float Float Float StartGrid
  1288.  
  1289.                 {
  1290.                         $$ = GeomMountainCreate($3, $4, (int)$5, $6, (int)$7, (int)$8, $9, $10);
  1291.                         if ($$)
  1292.                             $$->surf = $2;
  1293.                 }
  1294.                 | tMOUNTAIN Vec2d Vec2d Float Float Float Float Float StartGrid
  1295.                 {
  1296.                         $$ = GeomMountainCreate($2, $3, (int)$4, $5, (int)$6, (int)$7, $8, $9);
  1297.                 }
  1298.                 ;
  1299. HeightValues    : HeightValues Float
  1300.                 {
  1301.                        $$ = (HeightValue *)Malloc(sizeof(HeightValue));
  1302.                        $$->Next  = $1;
  1303.                        $$->Value = $2;
  1304.                 }
  1305.                 | Float
  1306.                 {
  1307.                      $$ = (HeightValue *)Malloc(sizeof(HeightValue));
  1308.                      $$->Value = $1;
  1309.                       $$->Next  = NULL;
  1310.                 }
  1311.                 ;
  1312. StartGrid       : HeightValues
  1313.                 {
  1314.                        int    i,j,k;
  1315.                        HeightValue  *CurrHV, *CurrHV2;
  1316.                        for (i = 0, CurrHV = $1; CurrHV != NULL; CurrHV = CurrHV->Next, i++);
  1317.                        for (j = 1; j*j < i; j++);
  1318.                        if (j*j != i) RLerror(RL_ABORT, "Invalid number of startgridvalues: %d\n", i);
  1319.                        else {
  1320.                            $$ = (StartGridStruct *)share_malloc(sizeof(StartGridStruct));
  1321.                            if ($$) {
  1322.                                $$->Size = j-1;
  1323.                                CurrHV = $1;
  1324.                                $$->Data = AllocMatrix(Float, j, j);
  1325.                                for (i = 0; i < j; i++)
  1326.                                   for (k = 0; k < j; k++) {
  1327.                                         $$->Data[i][k] = CurrHV->Value;
  1328.                                         CurrHV2 = CurrHV;
  1329.                                         CurrHV = CurrHV->Next;
  1330.                                         free(CurrHV2);
  1331.                                   }
  1332.                            }
  1333.                        }
  1334.                 }
  1335.                 ;
  1336.  
  1337. FractalObject:  tFRACTALOBJECT OptSurface Float Float Float Float FFractalClosure
  1338.                 {
  1339.                    $$ = GeomFractalObjCreate((int)$3, $4, $5, $6, $7);
  1340.                    if ($$)
  1341.                        $$->surf = $2;
  1342.                 }
  1343.                 ;
  1344. FFractalClosure: FPointPool FTrianglePool FEntityPool
  1345.                 {
  1346.                     $$ = (FractalClosure *)share_malloc(sizeof(FractalClosure));
  1347.                     $$->Pointpool = $1;
  1348.                     $$->Trianglepool = $2;
  1349.                     $$->Entitypool = $3;
  1350.                 }
  1351.                 ;
  1352. FPointPool:  tFPOINTS 
  1353.              {
  1354.                 Pointpool = (PointPool *)share_malloc(sizeof(PointPool));
  1355.                 Pointpool->Points = (FractalPoint *)share_malloc(PointsToAllocate * sizeof(FractalPoint));
  1356.                 Pointpool->NumberOfPoints = 0;
  1357.                 Pointpool->PointsAllocated = PointsToAllocate;
  1358.              }
  1359.              FPoints
  1360.              {
  1361.                 $$ = Pointpool;
  1362.              }
  1363.              ;
  1364. FPoints:   FPoint
  1365.            {
  1366.            }
  1367.            | FPoint FPoints
  1368.            {
  1369.            }
  1370.            ;
  1371. FPoint:  Float Float Float
  1372.          {
  1373.              CheckPoints(Pointpool->Points, Pointpool->NumberOfPoints, Pointpool->PointsAllocated);
  1374.              CurrPoint = &Pointpool->Points[Pointpool->NumberOfPoints++];
  1375.              CurrPoint->x = $1;
  1376.              CurrPoint->y = $2;
  1377.              CurrPoint->z = $3;
  1378.          }
  1379.          ;
  1380. FTrianglePool:  tFTRIANGLES
  1381.              {
  1382.                 Trianglepool = (TrianglePool *)share_malloc(sizeof(TrianglePool));
  1383.                 Trianglepool->Triangles = (FractalTriangle *)share_malloc(TrianglesToAllocate * sizeof(FractalTriangle));
  1384.                 Trianglepool->NumberOfTriangles = 0;
  1385.                 Trianglepool->TrianglesAllocated = TrianglesToAllocate;
  1386.              }
  1387.              FTriangles
  1388.              {
  1389.                 $$ = Trianglepool;
  1390.              }
  1391.              ;
  1392. FTriangles: FTriangle
  1393.             {
  1394.             }
  1395.             | FTriangle FTriangles
  1396.             {
  1397.             }
  1398.             ;
  1399. FTriangle:  Float Float Float
  1400.             {
  1401.                 CheckTriangles(Trianglepool->Triangles, Trianglepool->NumberOfTriangles,
  1402.                                Trianglepool->TrianglesAllocated);
  1403.                 CurrTriangle = &Trianglepool->Triangles[Trianglepool->NumberOfTriangles++];
  1404.                 CurrTriangle->Point[0] = $1 - 1;
  1405.                 CurrTriangle->Point[1] = $2 - 1;
  1406.                 CurrTriangle->Point[2] = $3 - 1;
  1407.             }
  1408.             ;
  1409. FEntityPool:  tFENTITIES
  1410.              {
  1411.                 Entitypool = (EntityPool *)share_malloc(sizeof(EntityPool));
  1412.                 Entitypool->Entities = (FractalEntity *)share_malloc(EntitiesToAllocate * sizeof(FractalEntity));
  1413.                 Entitypool->NumberOfEntities = 0;
  1414.                 Entitypool->EntitiesAllocated = EntitiesToAllocate;
  1415.              } 
  1416.              FEntities
  1417.              {
  1418.                 $$ = Entitypool;
  1419.              } 
  1420.              ;
  1421. FEntities: FEntity
  1422.            {
  1423.            }
  1424.            | FEntity FEntities
  1425.            {
  1426.            }
  1427.            ;
  1428. FEntity:  tENTITY Float Float Float FEntityTriangles
  1429.           {
  1430.               CheckEntities(Entitypool->Entities, Entitypool->NumberOfEntities,
  1431.                                Entitypool->EntitiesAllocated);
  1432.               CurrEntity = &Entitypool->Entities[Entitypool->NumberOfEntities++];
  1433.               CurrEntity->XSize = $2;
  1434.               CurrEntity->YSize = $3;
  1435.               CurrEntity->ZSize = $4;
  1436.               CurrEntity->Triangles = $5;
  1437.           }
  1438.           ;
  1439. FEntityTriangles: Float
  1440.                   {
  1441.                       $$ = (TriangleList *)share_malloc(sizeof(TriangleList));
  1442.                       $$->TriangleNumber = $1 - 1;
  1443.                       $$->Next = NULL;
  1444.                   }
  1445.                   | FEntityTriangles Float
  1446.                   {
  1447.                       $$ = (TriangleList *)share_malloc(sizeof(TriangleList));
  1448.                       $$->TriangleNumber = $2 - 1;
  1449.                       $$->Next = $1;
  1450.                   }
  1451.                   ;
  1452.  
  1453. Aggregate    : AggregateDef
  1454.         {
  1455.             if (Defstack->obj) {
  1456.                 /*
  1457.                  * Set object texture to current texture.
  1458.                  */
  1459.                 Defstack->obj->texture = CurText;
  1460.             }
  1461.             CurText = (Texture *)NULL;
  1462.             /*
  1463.              * Pop topmost object on stack.
  1464.              */
  1465.             $$ = Defstack->obj;
  1466.             Defstack = GeomStackPop(Defstack);
  1467.             /* Pop current surface */
  1468.             CurSurf = SurfPop(CurSurf);
  1469.             /* Make current default surf aggregate's default */
  1470.             $$->surf = CurSurf->surf;
  1471.         }
  1472.         ;
  1473. AggregateDef    : AggregateCreate Aggdefs tEND
  1474.         {
  1475.             /* Convert aggregate, pop stacks, etc. */
  1476.             if ($1) {
  1477.                 if (Defstack->obj->next == (Geom *)NULL) {
  1478.                     RLerror(RL_WARN,
  1479.                         "Null object defined.\n");
  1480.                     Defstack->obj = (Geom *)NULL;
  1481.                 } else {
  1482.                     /*
  1483.                      * Convert the linked list of objects
  1484.                      * associated with the topmost object
  1485.                      * to the appropriate aggregate type.
  1486.                      */
  1487.                     Defstack->obj->prims=AggregateConvert(
  1488.                         Defstack->obj,
  1489.                         Defstack->obj->next);
  1490.                     /*
  1491.                      * Make sure conversion worked OK.
  1492.                      */
  1493.                     if (Defstack->obj->prims <= 0)
  1494.                         Defstack->obj = (Geom *)NULL;
  1495.                 }
  1496.             }
  1497.         }
  1498.         ;
  1499. AggregateCreate    : AggregateType
  1500.         {
  1501.             if ($1) {
  1502.                 Defstack = GeomStackPush($1, Defstack);
  1503.                 CurSurf = SurfPush((Surface *)NULL, CurSurf);
  1504.             }
  1505.         };
  1506. AggregateType    : List
  1507.         | Grid
  1508.         | Csg
  1509.         ;
  1510. List        : tLIST
  1511.         {
  1512.             $$ = GeomListCreate();
  1513.         }
  1514.         ;
  1515. Grid        : tGRID IExpr IExpr IExpr
  1516.         {
  1517.             $$ = GeomGridCreate($2, $3, $4);
  1518.         }
  1519.         ;
  1520. Csg        : CombineOp
  1521.         {
  1522.             $$ = GeomCsgCreate($1);
  1523.             Options.csg = TRUE;
  1524.         }
  1525.         ;
  1526. CombineOp    : tUNION
  1527.         {
  1528.             $$ = CSG_UNION;
  1529.         }
  1530.         | tINTERSECT
  1531.         {
  1532.             $$ = CSG_INTERSECT;
  1533.         }
  1534.         | tDIFFERENCE
  1535.         {
  1536.             $$ = CSG_DIFFERENCE;
  1537.         }
  1538.             ;
  1539. Cone        : tCONE OptSurface Expr Vector Expr Vector
  1540.         {
  1541.             if (equal($3, $5)) {
  1542.                 /* It's really a cylinder */
  1543.                 $$ = GeomCylinderCreate($3, &$4, &$6);
  1544.             } else
  1545.                 $$ = GeomConeCreate($3, &$4, $5, &$6);
  1546.             if ($$)
  1547.                 $$->surf = $2;
  1548.         }
  1549.         ;
  1550. Cylinder    : tCYL OptSurface Expr Vector Vector
  1551.         {
  1552.             $$ = GeomCylinderCreate($3, &$4, &$5);
  1553.             if ($$)
  1554.                 $$->surf = $2;
  1555.         }
  1556.         ;
  1557. Sphere        : tSPHERE OptSurface Expr Vector
  1558.         {
  1559.             $$ = GeomSphereCreate($3, &($4));
  1560.             if ($$)
  1561.                 $$->surf = $2;
  1562.         }
  1563.         ;
  1564. Flame        : tFLAME Expr Vector Expr Expr
  1565.         {
  1566.             $$ = GeomFlameCreate($2, &($3), (int)$4, $5);
  1567.         }
  1568.         ;
  1569. Disc        : tDISC OptSurface Expr Vector Vector
  1570.         {
  1571.             $$ = GeomDiscCreate($3, &($4), &($5));
  1572.             if ($$)
  1573.                 $$->surf = $2;
  1574.         }
  1575.         ;
  1576. Box        : tBOX OptSurface Vector Vector
  1577.         {
  1578.             $$ = GeomBoxCreate(&$3, &$4);
  1579.             if ($$)
  1580.                 $$->surf = $2;
  1581.         }
  1582.         ;
  1583. Triangle    : tTRIANGLE OptSurface Vector Vector Vector
  1584.         {
  1585.             $$ = GeomTriangleCreate(FLATTRI, &($3), &($4), &($5),
  1586.                 (Vector *)NULL, (Vector *)NULL, (Vector *)NULL,
  1587.                 (Vec2d *)NULL, (Vec2d *)NULL, (Vec2d *)NULL,
  1588.                 Options.flipnorm);
  1589.             if ($$)
  1590.                 $$->surf = $2;
  1591.         }
  1592.         | tTRIANGLE OptSurface  Vector Vector
  1593.                     Vector Vector
  1594.                     Vector Vector
  1595.         {
  1596.             $$ = GeomTriangleCreate(PHONGTRI, &($3), &($5),
  1597.                 &($7), &($4), &($6), &($8),
  1598.                 (Vec2d *)NULL, (Vec2d *)NULL, (Vec2d *)NULL,
  1599.                 Options.flipnorm);
  1600.             if ($$)
  1601.                 $$->surf = $2;
  1602.         }
  1603.         | tTRIANGLEUV OptSurface Vector Vector Vec2d
  1604.                      Vector Vector Vec2d
  1605.                      Vector Vector Vec2d
  1606.         {
  1607.             $$ = GeomTriangleCreate(PHONGTRI, &($3), &($6), &($9),
  1608.                         &($4), &($7), &($10),
  1609.                         &($5), &($8), &($11),
  1610.                         Options.flipnorm);
  1611.             if ($$)
  1612.                 $$->surf = $2;
  1613.         }
  1614.         ;
  1615. Plane        : tPLANE OptSurface Vector Vector
  1616.         {
  1617.             $$ = GeomPlaneCreate(&($3), &($4));
  1618.             if ($$)
  1619.                 $$->surf = $2;
  1620.         }
  1621.         ;
  1622. Torus        : tTORUS OptSurface Expr Expr Vector Vector
  1623.         {
  1624.             $$ = GeomTorusCreate($3, $4, &($5), &($6));
  1625.             if ($$)
  1626.                 $$->surf = $2;
  1627.         }
  1628.         ;
  1629. Blob        : tBLOB OptSurface Expr MetaPoints
  1630.         {
  1631.             $$ = GeomBlobCreate($2, $3, Metapoints, Npoints);
  1632.             if ($$)
  1633.                 $$->surf = $2;
  1634.             Metapoints = (MetaList *)NULL;
  1635.             Npoints = 0;
  1636.         }
  1637.         ;
  1638. MetaPoints    : /* empty */
  1639.         | MetaPoints MetaPoint
  1640.         ;
  1641. MetaPoint    : Expr Expr Expr Expr Expr
  1642.         {
  1643.             Metapoint = (MetaList *)Malloc(sizeof(MetaList));
  1644.             Metapoint->mvec.c0 = $1; /* strength */
  1645.             Metapoint->mvec.rs = $2; /* radius**2 */
  1646.             Metapoint->mvec.x = $3;  /* coordinates of metaball */
  1647.             Metapoint->mvec.y = $4;  /* centers.                */
  1648.             Metapoint->mvec.z = $5;
  1649.             Metapoint->mvec.surf = NULL;
  1650.             /*Metapoint->mvec.mcolor.red = 1.0; */
  1651.             /*Metapoint->mvec.mcolor.green = 1.0; */
  1652.             /*Metapoint->mvec.mcolor.blue = 1.0; */
  1653.             Metapoint->next = Metapoints;
  1654.             Metapoints = Metapoint;
  1655.             Npoints++;
  1656.         }
  1657.         ;
  1658. Ifs        : IfsKey OptSurface IfsTransforms IfsOptions tEND
  1659.         {
  1660.             $$ = GeomIfsCreate($3, &ifsOptions);
  1661.             if ($$) 
  1662.                 $$->surf = $2;
  1663.         }
  1664.         ;
  1665. CIfs        : IfsKey OptSurface IfsCondensation IfsLeaves IfsTransforms IfsOptions tEND
  1666.         {
  1667.             $$ = GeomCIfsCreate($5, $3, $4, &ifsOptions);
  1668.             if ($$) 
  1669.                 $$->surf = $2;
  1670.         }
  1671.         ;
  1672. IfsKey          : tIFS  /* set option defaults */
  1673.                 {
  1674.                         ifsTransformRang = 1;
  1675.                         ifsOptions.depth = 99999999;
  1676.                         ifsOptions.size = 0.;
  1677.                         ifsOptions.normalweighting = HIGHPASS_NORMAL_WEIGHTING;
  1678.             ifsOptions.boxbounding = ifsOptions.spherebounding = FALSE;
  1679.             ifsOptions.listfilename = NULL;
  1680.                 }
  1681.                 ;
  1682. IfsCondensation    : TransTextObj ','
  1683.         {
  1684.             $$ = $1;
  1685.         }
  1686.         ;
  1687. IfsLeaves       : TransTextObj ',' /* Oppenheimer trees */
  1688.                 {
  1689.                         $$ = $1;
  1690.                 }
  1691.                 | /* no leaves -> a true IFS */
  1692.                 {
  1693.                         $$ = (Geom *)NULL;
  1694.                 }
  1695.                 ;
  1696. IfsTransforms    : OptIfsTransformRang IfsTransform
  1697.         {
  1698.             $$ = (IfsTransList *)Malloc(sizeof(IfsTransList));
  1699.             $$->trans = TransHead;
  1700.             $$->transtail = TransTail;
  1701.             $$->next = (IfsTransList *)NULL;
  1702.                         $$->rang = ifsTransformRang;
  1703.         }
  1704.         | IfsTransforms ',' OptIfsTransformRang IfsTransform
  1705.         {
  1706.             $$ = (IfsTransList *)Malloc(sizeof(IfsTransList));
  1707.             $$->trans = TransHead;
  1708.             $$->transtail = TransTail;
  1709.             $$->next = $1;
  1710.                         $$->rang = ifsTransformRang;
  1711.         }
  1712.         ;
  1713. IfsTransform    : TransformType
  1714.         {
  1715.             TransHead = TransTail = $1;
  1716.         }
  1717.         | IfsTransform PostTransform
  1718.         ;
  1719. OptIfsTransformRang : IExpr
  1720.                 {
  1721.                         ifsTransformRang = $1;
  1722.                 }
  1723.                 | /* no rang specified */
  1724.                 ;
  1725. IfsOptions      : /* no options */
  1726.                 | IfsOptions tMINSIZE Expr
  1727.                 {
  1728.                         ifsOptions.size = $3;
  1729.                 }
  1730.                 | IfsOptions tMAXDEPTH IExpr
  1731.                 {
  1732.                         ifsOptions.depth = $3;
  1733.                 }
  1734.                 | IfsOptions tNORMALWEIGHTING IfsNormalWeightingMethod
  1735.                 {
  1736.                         ifsOptions.normalweighting = $3;
  1737.         }
  1738.         | IfsOptions tBOUNDING IfsBoundingVolumeType
  1739.         {
  1740.         }
  1741.         | IfsOptions tLIST Filename
  1742.         {
  1743.             ifsOptions.listfilename = strsave($3);
  1744.         }
  1745.                 ;
  1746. IfsNormalWeightingMethod: tCONSTANT
  1747.                 {
  1748.                         $$ = CONSTANT_NORMAL_WEIGHTING;
  1749.                 }
  1750.                 | tLOWPASS
  1751.                 {
  1752.                         $$ = LOWPASS_NORMAL_WEIGHTING;
  1753.                 }
  1754.                 | tHIGHPASS
  1755.                 {
  1756.                         $$ = HIGHPASS_NORMAL_WEIGHTING;
  1757.                 }
  1758.                 ;
  1759. IfsBoundingVolumeType:    tBOX
  1760.         {
  1761.             ifsOptions.boxbounding = TRUE;
  1762.             ifsOptions.spherebounding = FALSE;
  1763.         }
  1764.         | tSPHERE
  1765.         {
  1766.             ifsOptions.boxbounding = FALSE;
  1767.             ifsOptions.spherebounding = TRUE;
  1768.         }
  1769.         ;
  1770. CBlob        : tCBLOB OptSurface Expr CMetaPoints
  1771.         {
  1772.             $$ = GeomBlobCreate($2, $3, CMetapoints, Npoints);
  1773.             if ($$)
  1774.                 $$->surf = $2;
  1775.             CMetapoints = (MetaList *)NULL;
  1776.             Npoints = 0;
  1777.         }
  1778.         ;
  1779. CMetaPoints    : /* empty */
  1780.         | CMetaPoints CMetaPoint
  1781.         ;
  1782. CMetaPoint    : Expr Expr Expr Expr Expr OptSurface
  1783.         {
  1784.             CMetapoint = (MetaList *)Malloc(sizeof(MetaList));
  1785.             CMetapoint->mvec.c0 = $1; /* strength */
  1786.             CMetapoint->mvec.rs = $2; /* radius**2 */
  1787.             CMetapoint->mvec.x = $3;  /* coordinates of metaball */
  1788.             CMetapoint->mvec.y = $4;  /* centers.                */
  1789.             CMetapoint->mvec.z = $5;
  1790.             CMetapoint->mvec.surf = $6; /*OptSurface */
  1791.             /*CMetapoint->mvec.mcolor.red = $6; */
  1792.             /*CMetapoint->mvec.mcolor.green = $7; */
  1793.             /*CMetapoint->mvec.mcolor.blue = $8; */
  1794.             CMetapoint->next = CMetapoints;
  1795.             CMetapoints = CMetapoint;
  1796.             Npoints++;
  1797.         }
  1798.         ;
  1799. Rotspline       : tROTSPLINE OptSurface Vector Vector
  1800.                         tCOEFFS Expr Expr Expr Expr
  1801.                 {
  1802.                         Rcoeffs = (Float *)Calloc(4, sizeof(Float));
  1803.                         Rcoeffs[0] = $9;
  1804.                         Rcoeffs[1] = $8;
  1805.                         Rcoeffs[2] = $7;
  1806.                         Rcoeffs[3] = $6;
  1807.                         $$ = GeomRotsplineCreate(&($3), 0.0, 0.0,
  1808.                                                 &($4), 0.0, 0.0, Rcoeffs);
  1809.                         if ($$)
  1810.                                 $$->surf = $2;
  1811.                         Rcoeffs = (Float *)NULL;
  1812.                 }
  1813.                 | tROTSPLINE OptSurface Vector Expr Expr
  1814.                                         Vector Expr Expr
  1815.                 {
  1816.                         $$ = GeomRotsplineCreate(&($3), $4, $5,
  1817.                                                 &($6), $7, $8, (Float *)NULL);
  1818.                         if ($$)
  1819.                                 $$->surf = $2;
  1820.                 }
  1821.                 ;
  1822. Outfile        : tOUTFILE Filename
  1823.         {
  1824.             if (Options.imgname != (char *)NULL)
  1825.                 /* Already set on command line. */
  1826.                 RLerror(RL_WARN,
  1827.                     "Ignoring output file name \"%s\".\n",
  1828.                     $2);
  1829.             else
  1830.                 Options.imgname = strsave($2);
  1831.         }
  1832.         ;
  1833. GlobalEffects    : tATMOSPHERE Effects
  1834.         {
  1835.             AtmosEffects = CurEffect;
  1836.             CurEffect = (Atmosphere *)NULL;
  1837.         }
  1838.         | tATMOSPHERE IExpr Effects
  1839.         {
  1840.             if ($2 <= 0.)
  1841.                 RLerror(RL_PANIC,
  1842.                 "Index of refraction must be positive.\n");
  1843.             TopMedium.index = $2;
  1844.             AtmosEffects = CurEffect;
  1845.             CurEffect = (Atmosphere *)NULL;
  1846.         }
  1847.         ;
  1848. Effects        : Effects Effect
  1849.         |
  1850.         ;
  1851. Effect        : EffectType
  1852.         {
  1853.             $1->next = CurEffect;
  1854.             CurEffect = $1;
  1855.         }
  1856.         ;
  1857. EffectType    : tMIST Color Color Expr Expr
  1858.         {
  1859.             $$ = AtmosMistCreate(&($2), &($3), $4, $5);
  1860.         }
  1861.         | tFOG Color Color
  1862.         {
  1863.             $$ = AtmosFogCreate(&($2), &($3));
  1864.         }
  1865.         | tFOGDECK Expr Expr Vector Expr IExpr Color Color
  1866.         {
  1867.             $$ = AtmosFogdeckCreate($2, $3, &$4, $5, $6, &$7, &$8);
  1868.         }
  1869.         ;
  1870. Color        : Expr Expr Expr
  1871.         {
  1872.             $$.r = $1;
  1873.             $$.g = $2;
  1874.             $$.b = $3;
  1875.         }
  1876.         ;
  1877. Vector        : Expr Expr Expr
  1878.         {
  1879.             $$.x = $1;
  1880.             $$.y = $2;
  1881.             $$.z = $3;
  1882.         }
  1883.         ;
  1884. Vec2d        : Expr Expr 
  1885.         {
  1886.             $$.u = $1;
  1887.             $$.v = $2;
  1888.         }
  1889.         ;
  1890. OptMapping    : Mapping
  1891.         | /* EMPTY */
  1892.         {
  1893.             $$ = UVMappingCreate();
  1894.         }
  1895.         ;
  1896. Mapping        : tMAP MapMethod
  1897.         {
  1898.             $$ = $2;
  1899.         }
  1900.         ;
  1901. MapMethod    : tUV
  1902.         {
  1903.             $$ = UVMappingCreate();
  1904.         }
  1905.         | tSPHERICAL
  1906.         {
  1907.             $$ = SphereMappingCreate((Vector *)NULL,
  1908.                 (Vector *)NULL, (Vector *)NULL);
  1909.         }
  1910.         | tSPHERICAL Vector Vector Vector
  1911.         {
  1912.             /* origin up uaxis */
  1913.             $$ = SphereMappingCreate(&$2, &$3, &$4);
  1914.         }
  1915.         | tCYLINDRICAL
  1916.         {
  1917.             $$ = CylMappingCreate((Vector *)NULL,
  1918.                 (Vector *)NULL, (Vector *)NULL);
  1919.         }
  1920.         | tCYLINDRICAL Vector Vector Vector
  1921.         {
  1922.             /* origin up uaxis */
  1923.             $$ = CylMappingCreate(&$2, &$3, &$4);
  1924.         }
  1925.         | tPLANAR
  1926.         {
  1927.             $$ = LinearMappingCreate((Vector *)NULL,
  1928.                 (Vector *)NULL, (Vector *)NULL);
  1929.         }
  1930.         | tPLANAR Vector Vector Vector
  1931.         {
  1932.             /* origin up uaxis */
  1933.             $$ = LinearMappingCreate(&$2, &$3, &$4);
  1934.         }
  1935.         ;
  1936. SurfCompName    : tAMBIENT
  1937.         {
  1938.             $$ = AMBIENT;
  1939.         }
  1940.         | tDIFFUSE
  1941.         {
  1942.             $$ = DIFFUSE;
  1943.         }
  1944.         | tBODY
  1945.         {
  1946.             $$ = BODY;
  1947.         }
  1948.         | tSPECULAR
  1949.         {
  1950.             $$ = SPECULAR;
  1951.         }
  1952.         | tREFLECT
  1953.         {
  1954.             $$ = REFLECT;
  1955.         }
  1956.         | tTRANSP
  1957.         {
  1958.             $$ = TRANSP;
  1959.         }
  1960.         | tSPECPOW
  1961.         {
  1962.             $$ = SPECPOW;
  1963.         }
  1964.         | tBUMP
  1965.         {
  1966.             $$ = BUMP;
  1967.         }
  1968.         | tINDEX
  1969.         {
  1970.             $$ = INDEX;
  1971.         }
  1972.         ;
  1973. Intensity    : Expr
  1974.         { $$.r = $$.g = $$.b = $1; }
  1975.         | Color
  1976.         ;
  1977. Print        : tPRINT Expr
  1978.         {
  1979.             fprintf(stderr,"%f\n",$2);
  1980.         }
  1981. Define        : tDEFINE tSTRING AnimExpr
  1982.         {
  1983.             SymtabAddEntry($2, $3->type, $3, NULL, $3->timevary, 0);
  1984.         };
  1985. IExpr        : Expr
  1986.         { $$ = (int)$1; }
  1987.         ;
  1988. BExpr        : tTRUE
  1989.         { $$ = 1; }
  1990.         | tFALSE
  1991.         { $$ = 0; }
  1992.         ;
  1993. Expr        : Float
  1994.         | ParenExpr
  1995.         {
  1996.             if (!$1->timevary) {
  1997.                 $$ = ExprEval($1);
  1998.             } else {
  1999.                 RLerror(RL_PANIC, "Illegal expression use.\n");
  2000.             }
  2001.         }
  2002.         ;
  2003. AnimExpr    : Float
  2004.         {
  2005.             $$ = ExprReuseFloatCreate($1);
  2006.         }
  2007.         | ParenExpr
  2008.         ;
  2009. ParenExpr    : '(' MExpr ')'
  2010.         {
  2011.             $$ = $2;
  2012.         };
  2013. MExpr        : tFLOAT
  2014.         {
  2015.             $$ = ExprFloatCreate($1, FALSE);
  2016.         }
  2017.         | tSTRING
  2018.         {
  2019.             $$ = ExprFloatSymtabFind($1);
  2020.         }
  2021.         | Symtabent '(' MExpr ')'
  2022.         {
  2023.             $$ = ExprResolve1($3, $1->value.fp, $1->timevary);
  2024.         }
  2025.         | Symtabent '(' MExpr ',' MExpr ')'
  2026.         {
  2027.             $$ = ExprResolve2($3, $5,
  2028.                     $1->value.fp,
  2029.                     $1->timevary);
  2030.         }
  2031.         | Symtabent '(' MExpr ',' MExpr ',' MExpr ')'
  2032.         {
  2033.             $$ = ExprResolve3($3, $5, $7, 
  2034.                     $1->value.fp,
  2035.                     $1->timevary);
  2036.         }
  2037.         | Symtabent '(' MExpr ',' MExpr ',' MExpr ',' MExpr ')'
  2038.         {
  2039.             $$ = ExprResolve4($3, $5, $7, $9, 
  2040.                     $1->value.fp,
  2041.                     $1->timevary);
  2042.         }
  2043.         | Symtabent
  2044.             '(' MExpr ',' MExpr ',' MExpr ',' MExpr ',' MExpr ')'
  2045.         {
  2046.             $$ = ExprResolve5($3, $5, $7, $9, $11,
  2047.                     $1->value.fp,
  2048.                     $1->timevary);
  2049.         }
  2050.         | '(' MExpr ')'
  2051.         {
  2052.             $$ = $2;
  2053.         }
  2054.         | MExpr '+' MExpr
  2055.         {
  2056.             $$ = ExprResolve2($1, $3, SumExpr, FALSE);
  2057.         }
  2058.         | MExpr '-' MExpr
  2059.         {
  2060.             $$ = ExprResolve2($1, $3, DiffExpr, FALSE);
  2061.         }
  2062.         | MExpr '*' MExpr
  2063.         {
  2064.             $$ = ExprResolve2($1, $3, MultExpr, FALSE);
  2065.         }
  2066.         | MExpr '/' MExpr
  2067.         {
  2068.             $$ = ExprResolve2($1, $3, DivideExpr, FALSE);
  2069.         }
  2070.         | MExpr '%' MExpr
  2071.         {
  2072.             $$ = ExprResolve2($1, $3, ModExpr, FALSE);
  2073.         }
  2074.         | '-' MExpr %prec UMINUS
  2075.         {
  2076.             $$ = ExprResolve1($2, NegateExpr, FALSE);
  2077.         }
  2078.         | '+' MExpr %prec UMINUS
  2079.         {
  2080.             $$ = $2;
  2081.         }
  2082.         | MExpr '^' MExpr
  2083.         {
  2084.             $$ = ExprResolve2($1, $3, pow, FALSE);
  2085.         } ;
  2086. Float        : tFLOAT
  2087.         | '-' tFLOAT
  2088.         { $$ = -$2; }
  2089.         | '+' tFLOAT
  2090.         { $$ = $2; };
  2091. Filename    : tSTRING
  2092.         | tFILENAME
  2093.         ;
  2094. Symtabent    : tSTRING
  2095.         {
  2096.             $$ = SymtabBuiltinFind($1);
  2097.         }
  2098.         | tLINEAR
  2099.         {
  2100.             $$ = SymtabBuiltinFind(strsave("linear"));
  2101.         };
  2102. %%
  2103. /*
  2104.  * Issue error message containing filename and line number, and exit.
  2105.  */
  2106. /*VARARGS1*/
  2107. yyerror(s, pat1, pat2)
  2108. char *s, *pat1, *pat2;
  2109. {
  2110.     fprintf(stderr,"%s: Error: %s: line %d: ", Options.progname,
  2111.             yyfilename, yylineno);
  2112.     fprintf(stderr, s, pat1, pat2);
  2113.     if (*s && s[strlen(s) -1] != '\n')
  2114.         /* YACC doesn't put newlines on error messages. */
  2115.         fprintf(stderr,"\n");    
  2116.     fflush(stderr);
  2117.     exit(1);
  2118. }
  2119.  
  2120. Geom *
  2121. NewAggregate(obj)
  2122. Geom *obj;
  2123. {
  2124.     obj->name = Defstack->obj->name;
  2125.     obj->next = Defstack->obj->next;
  2126.     return obj;
  2127. }
  2128.